package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.ShopGoodListBeen;
import cn.xfdzx.android.apps.shop.contract.GoodActionCallback;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;

/**
 * @author gzk
 * @date 2020/3/27 0027
 * description：社区零售的适配器
 */
public class ShopRetailRightAdapter extends RecyclerView.Adapter {

    private ItemClickListener mItemClickListener;


    private ArrayList<ShopGoodListBeen.DataBean.GoodsInfoBean> mList;


    private Context mContext;
    private final LayoutInflater mLayoutInflater;
    private GoodActionCallback callback;
    private String shopId;

    public ShopRetailRightAdapter(Context mContext, ArrayList<ShopGoodListBeen.DataBean.GoodsInfoBean> mList, GoodActionCallback callback,String shopId) {
        this.mContext = mContext;
        this.mList = mList;
        this.callback = callback;
        this.shopId = shopId;
        //以后用它来初始化布局
        mLayoutInflater = LayoutInflater.from(mContext);

    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//        if (viewType == TYPE_TITLE) {
//            return new ShopTitleViewHolder(mContext, mLayoutInflater.inflate(R.layout.item_title, null));
//        }else if (viewType == TYPE_CONTENT) {
//            return new ShopContentViewHolder(mContext, mLayoutInflater.inflate(R.layout.item_selling_goods_right, null),callback);
//        }
        return new ShopContentViewHolder(mContext, mLayoutInflater.inflate(R.layout.item_selling_goods_right, null), callback);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {


        ((ShopContentViewHolder) holder).setData(mList.get(position), position,shopId);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                mItemClickListener.onItemClick(position);
            }
        });

    }


    @Override
    public int getItemCount() {
        return mList.size();
    }


    public void setOnItemClickListener(ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;

    }
}
